<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商铺" prop="code">
        <!-- <el-select v-model="queryParams.shopsId" placeholder="请选择商铺" clearable>
          <el-option v-for="dict in shopsList" :key="dict.id" :label="dict.code" :value="dict.id" />
        </el-select> -->
        <HouseInput v-model="queryParams.code" type="house" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-form :model="shops" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item>
        <div class="myDiv">
          <div style="width:200px">编号：<span>{{ cashregisterList[0].code }}</span></div>

          <div>商铺状态：
            <span v-if="cashregisterList[0].zhwyShops != null">
              <span v-if="cashregisterList[0].zhwyShops.state == 0">空置</span>
              <span v-else-if="cashregisterList[0].zhwyShops.state == 1">已出租</span>
              <span v-else-if="cashregisterList[0].zhwyShops.state == 2">已出售</span>
              <span v-else-if="cashregisterList[0].zhwyShops.state == 3">即将到期</span>
              <span v-else-if="cashregisterList[0].zhwyShops.state == 4">租约预期</span>
            </span>

          </div>

          <div>占地面积：
            <span v-if="cashregisterList[0].zhwyShops != null">
              <span>{{ cashregisterList[0].zhwyShops.floorArea }}</span>
            </span>
          </div>
        </div>
        <div class="myDiv">
          <div>使用面积：
            <span v-if="cashregisterList[0].zhwyShops != null">
              <span>{{ cashregisterList[0].zhwyShops.useArea }}</span>
            </span>
          </div>

          <!-- （租售合同） -->
          <div>行业：
            <span v-if="cashregisterList[0].zhwyRentalcontract != null">
              <span>{{ cashregisterList[0].zhwyRentalcontract.trade }}</span>
            </span>
          </div>
          <!-- （租户信息） -->
          <div style="width:200px">客户姓名：
            <span v-if="cashregisterList[0].zhwyHirer != null">
              <span>{{ cashregisterList[0].zhwyHirer.name }}</span>
            </span>
          </div>
        </div>

        <div class="myDiv">
          <!-- (租户信息) -->
          <div>联系方式：
            <span v-if="cashregisterList[0].zhwyHirer != null">
              <span>{{ cashregisterList[0].zhwyHirer.phone }}</span>
            </span>
          </div>
        </div>

      </el-form-item>
    </el-form>


    <el-tabs v-model="activeName" @tab-click="handleClick">
      
      <el-tab-pane label="临时收费/收取押金" name="second">
        <!-- 临时收费/收取押金 -->
        <TDeposit v-model="cmValue" v-if="mySta"></TDeposit>
      </el-tab-pane>


      <el-tab-pane label="预存款" name="fourth">
        <!-- 预存款 -->
        <ADeposit v-model="cmValue" v-if="mySta"></ADeposit>
      </el-tab-pane>
    </el-tabs>



  </div>
</template>

<script>
import { listCashregister, getCashregister, delCashregister, addCashregister, updateCashregister } from "@/api/msr/cashregister";
import { listChargeitem, getChargeitem, delChargeitem, addChargeitem, updateChargeitem } from "@/api/hyj/chargeitem";
import { listShops, getShops } from "@/api/system/shops";
export default {
  name: "Cashregister",
  data() {
    return {
      cmValue:null,
      mySta:false,
      activeName: 'second',
      //商铺列表
      shopsList: [],
      //商铺对象
      shops: {},

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 综合收银表格数据
      cashregisterList: [{
        code: null,
        zhwyShops: {
          state: null,
          floorArea: null,
        },
        zhwyRentalcontract: {
          trade: null
        },
        zhwyHirer: {
          name: null,
          phone: null
        }

      }],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    /** 查询综合收银列表 */
    getList() {
      this.loading = true;
      listCashregister(this.queryParams).then(response => {
        this.cashregisterList = response.rows;
        this.total = response.total;
        this.loading = false;
        if(this.queryParams.code!=null){
          this.cmValue=this.cashregisterList[0].zhwyShops.id
          this.mySta=true;
        }

      });
      /** 查询商铺信息管理列表 */
      listShops().then(response => {
        this.shopsList = response.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加综合收银";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCashregister(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改综合收银";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCashregister(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCashregister(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除综合收银编号为"' + ids + '"的数据项？').then(function () {
        return delCashregister(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('msr/cashregister/export', {
        ...this.queryParams
      }, `cashregister_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.myDiv {
  margin-left: 20px;
}

.myDiv div {
  display: inline-block;
  width: 200px;
  font-weight: bold;
}

.myDiv span {
  font-weight: bold;
  color: blueviolet;
}
</style>
